﻿@using AdvancedPoll.ViewModels;
@model PollViewModel

@using (Html.BeginFormAntiForgeryPost())
{
    @Html.ValidationSummary();
    
    <fieldset>
        <div id="editor-label">
            @Html.LabelFor(m => m.Question)
        </div>
        <div id="editor-field">
            @Html.TextBoxFor(m=>m.Question)
            @Html.ValidationMessageFor(m=>m.Question)
        </div>
        <div id="editor-label">
            @Html.LabelFor(m => m.Open)
        </div>
        <div id="editor-field">
            @Html.TextBoxFor(m=>m.Open)
            @Html.ValidationMessageFor(m=>m.Open)
        </div>
        <div id="editor-label">
            @Html.LabelFor(m => m.Close)
        </div>
        <div id="editor-field">
            @Html.TextBoxFor(m=>m.Close)
            @Html.ValidationMessageFor(m=>m.Close)
        </div>
        <div id="editor-label">
            @Html.LabelFor(m => m.MaxVotes)
        </div>
        <div id="editor-field">
            @Html.TextBoxFor(m=>m.MaxVotes)
            @Html.ValidationMessageFor(m=>m.MaxVotes)
        </div>
        <div id="editor-label">
            @Html.LabelFor(m => m.Shown)
        </div>
        <div id="editor-field">
            @Html.CheckBoxFor(m=>m.Shown)
            @Html.ValidationMessageFor(m=>m.Shown)
        </div>
        @{ var choiceIndex = 0; }
        @foreach (var c in Model.Choices)
        {
            <div id="editor-label">
                <label>Answer</label>
            </div>
            <div id="editor-field">
                @Html.HiddenFor(m => m.Choices[choiceIndex].Choice.Id)
                @Html.HiddenFor(m => m.Choices[choiceIndex].Action)
                @Html.TextBoxFor(m => m.Choices[choiceIndex].Choice.Answer)
            </div>
            choiceIndex = choiceIndex + 1;
        }
        <div id="editor-label">
            <label>New Answer</label>
        </div>
        <div id="editor-field">
            <input type="hidden" name="Choices[@choiceIndex].Choice.Id" value="0" />
            <input type="hidden" name="Choices[@choiceIndex].Action" value="Create" />
            <input type="text" name="Choices[@choiceIndex].Choice.Answer" value="" />
        </div>
        <input type="submit" name="submit.Poll" />
    </fieldset>
}